using System;
using MemoryPack;
using MessagePack;
using ProtoBuf;

namespace SerializeDemo;

public interface ICommand
{
    ReadOnlyMemory<byte> Encode();
}

[ProtoContract]
public struct UserRegisterstructRequest : ICommand
{
    [ProtoMember(1, IsRequired = true)]
    public string? Username { get; set; }

    [ProtoMember(2)]
    public string? Password { get; set; }

    [ProtoMember(3)]
    public string? Email { get; set; }

    [ProtoMember(4)]
    public uint QQ { get; set; }

    [ProtoMember(5)]
    public string? Content { get; set; }

    public ReadOnlyMemory<byte> Encode()
    {
        throw new NotImplementedException();
    }
}

[MemoryPackable]
[ProtoContract]
[MessagePackObject]
public partial class UserRegisterRequest 
{
    [Key(0)]
    [ProtoMember(1)]
    public string? Username { get; set; }

    [Key(1)]
    [ProtoMember(2)]
    public string? Password { get; set; }

    [Key(2)]
    [ProtoMember(3)]
    public string? Email { get; set; }

    [Key(3)]
    [ProtoMember(4)]
    public uint QQ { get; set; }

    [Key(4)]
    [ProtoMember(5)]
    public string? Content { get; set; }

    public ReadOnlySpan<byte> Encode()
    {
        return global::MemoryPack.MemoryPackSerializer.Serialize(this);
    }
}


[ProtoContract]
[MessagePackObject]
public struct UserRegisterMessage
{
    [Key(0)]
    [ProtoMember(1)]
    public required string? Username { get; set; }

    [Key(1)]
    [ProtoMember(2)]
    public required string? Password { get; set; }

    [Key(2)]
    [ProtoMember(3)]
    public required string? Email { get; set; }

    [Key(3)]
    [ProtoMember(4)]
    public required uint QQ { get; set; }

    [Key(4)]
    [ProtoMember(5)]
    public required string? Content { get; set; }
}